<?php namespace App\Http\Controllers\Admin;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class AdminController extends Controller {

    public function getIndex()
    {
        $allMenu = [
            'admin-system' => [
                'name' => '常规',
                'items' => [
//                    ['name' => '管理首页', 'node' => 'admin-sys-welcome'],
                    ['name' => '重置密码', 'node' => 'admin-sys-repass'],
                    ['name' => '清除缓存', 'node' => 'admin-sys-clearcache'],
                ],
            ],

            'admin-product' => [
                'name'  => "信息",
                'items' => [
                    ["name" => "一级分类管理", 'node' => 'admin-product-types-1'],
                    ["name" => "类别管理", 'node' => 'admin-product-types'],
                    ["name" => "信息管理", 'node' => 'admin-product'],
                    ["name" => "城市管理", 'node' => 'admin-product-region'],
                ]
            ],

            'admin-user' => [
                'name'  => "用户",
                'items' => [
                    ["name" => "门店管理", 'node' => 'admin-user-merchant'],
                    ["name" => "用户管理", 'node' => 'admin-user-customer'],
                ]
            ],

            'admin-content' => [
                'name'  => "内容",
                'items' => [
                    ["name" => "新闻管理", 'node' => 'admin-news'],
                ]
            ],

            'admin-his' => [
                'name'  => "记录",
                'items' => [
                    ["name" => "充值记录", 'node' => 'admin-his-recharge'],
                ]
            ],
        ];

        $menu = [];
        foreach($allMenu as $k => $v) {
            $sublink = [];
            foreach ($v['items'] as $node) {
                $sublink[] = $node;
            }

            if (count($sublink)) {
                $menu[$k]['name']   = $v['name'];
                $menu[$k]['id']     = $k;
                $menu[$k]['parent'] = 'root';

                $items = [];
                foreach($sublink as $s) {
                    $items[$s['node']] = [
                        'id'        => $s['node'],
                        'name'      => $s['name'],
                        'parent'    => $k,
                        'url'       => url(str_replace('-', '/', $s['node'])),
                    ];
                }

                $menu[$k]['items'] = $items;
            }
        }

        return view('admin.index', ['menu' => json_encode($menu, true)]);
    }

}
